class Solution {
public:
    vector<string> summaryRanges(vector<int>& nums) {
        int n = nums.size();
        if(n == 0)
            return {};
        int left = nums[0], right = nums[0];
        vector<string> ret;
        for(int i = 1; i < n; i++)
        {
            if(nums[i] == nums[i - 1] + 1)
                right = nums[i];
            else
            {
                if(left == right)
                    ret.push_back(to_string(left));
                else
                    ret.push_back(to_string(left) + "->" + to_string(right));
                left = right = nums[i];
            }
        }
        if(left == right)
            ret.push_back(to_string(left));
        else
            ret.push_back(to_string(left) + "->" + to_string(right));
        return ret;
    }
};